export function setSessionStorage(key, value) {
	if (key == undefined || key == null || key == '') {
		return
	}
	if (value == undefined || value == null || value == '') {
		sessionStorage.removeItem(key);
		return
	}
	if (typeof value == 'object') {
		value = JSON.stringify(value)
	}
	sessionStorage.setItem(key, value)
}

export function removeSessionStorage(key) {
	if (key == undefined || key == null || key == '') {
		return
	}
	sessionStorage.removeItem(key);
}

export function getJsonSessionStorage(key) {
	if (key == undefined || key == null || key == '') {
		return
	}
	let value = sessionStorage.getItem(key);
	if (value == undefined || value == null || value == '') {
		return
	}
	try {
		return JSON.parse(value)
	} catch (e) {
		console.error('parse json err', value)
	}
}

export function getLoginUser() {
	return getJsonSessionStorage('loginUser')
}

export function setLoginUser(user) {
	setSessionStorage('loginUser', user);
}

export function removeLoginUser() {
	removeSessionStorage('loginUser');
}
